package com.mason.forum.utils;


import org.apache.commons.codec.digest.DigestUtils;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-10-02
 * Time: 2:24
 */

/**
 * MD5加盐加密...
 */
public class MD5Utils {

    // 获取盐值
    public static String getSalt() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    // md5加密
    public static String md5(String normal) {
        return DigestUtils.md5Hex(normal);
    }

    // 加盐加密
    public static String encrypt(String salt, String password) {
        return md5(salt + password);
    }

    // 验证密码
    public static boolean confirm(String salt, String inputPassword, String dbPassword) {
        return dbPassword.equals(md5(salt + inputPassword));
    }

}
